/***********************************************************************
 * Module:  SpecialPlateController.java
 * Author:  Administrator
 * Purpose: Defines the Class SpecialPlateController
 ***********************************************************************/

package ishitong.vehicleManagement.controller;

import ishitong.vehicleManagement.model.SpecialPlate;
import ishitong.common.SysCodeType;
import ishitong.common.model.SysCode;
import ishitong.commons.pagination.Pagination;
import ishitong.vehicleManagement.model.SpecialPlateQuery;
import ishitong.vehicleManagement.service.biz.SpecialPlateService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.ishitong.platform.common.page.Page;

/** @pdOid 8fc8e98f-11fc-4c6a-bd4a-015c9340d676 */
@Controller
public class SpecialPlateController extends ishitong.common.controller.ActionController {
   /** @pdOid 4f76683d-9ac8-40b9-ae64-163fab9df2aa */
   private static final String SPE_PLA_SCH = "vehicleManagement/specialPlate/specialPlateSearch";
   /** @pdOid f9ae41bf-41f2-465f-a72d-9f5408efdcd1 */
   private static final String SPE_PLA_SCH_LST = "vehicleManagement/specialPlate/specialPlateSearchList";
   /** @pdOid 194f2fec-37b7-4ad7-b183-f6a00d8e6104 */
   private static final String SPE_PLA_EDT = "vehicleManagement/specialPlate/specialPlateEdit";
   /** @pdOid 23e8bd58-b256-4d7c-9d46-a64147d4fa0d */
   @Autowired
   private SpecialPlateService specialPlateService;
   
   /** @param request
    * @exception Exception
    * @pdOid d43e25d1-eae1-46d9-9b63-4a3a2f34934e */
   @RequestMapping(value = "/showSpecialPlateSearch.do")
   public ModelAndView handleShowSpecialPlateSearch(HttpServletRequest request) throws Exception {
   	try {
   		Map<String, Object> model = new HashMap<>();
   		// 号牌种类
   		List<SysCode> lstLicencePlateKind = spiSysCodeService.getSysCodeListByTypeCode(SysCodeType.PLATE_KIND); 
   		model.put("lstLicencePlateKind", lstLicencePlateKind);
   		// 匹配方式
   		List<SysCode> lstMatchWay = spiSysCodeService.getSysCodeListByTypeCode(SysCodeType.MATCH_WAY); 
   		model.put("lstMatchWay",lstMatchWay);
   
   		return new ModelAndView(SPE_PLA_SCH, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param specialPlateQuery 
    * @param pagination
    * @pdOid efac07cf-0a26-46cc-80b3-951b57a81046 */
   @RequestMapping(value = "/ajaxSpecialPlateSearchList.do")
   public ModelAndView handleAjaxFindSpecialPlateSelectList(HttpServletRequest request, SpecialPlateQuery specialPlateQuery, Pagination pagination) {
   	try {
   		Map<String, Object> model = new HashMap<>();
   		Page<SpecialPlate> page=this.specialPlateService.findPage(specialPlateQuery, pagination.getPageSize(), pagination.getCurrentPage());
   		model.put("page", page);
   		return new ModelAndView(SPE_PLA_SCH_LST, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param specialPlateId
    * @exception Exception
    * @pdOid 9fbddae5-4884-4af4-b81e-595074b385d6 */
   @RequestMapping(value = "/ajaxShowSpecialPlateEdit.do", method = RequestMethod.POST)
   public ModelAndView handleAjaxShowSpecialPlateEdit(HttpServletRequest request, String specialPlateId) throws Exception {
   	try {
   		Map<String, Object> model = new HashMap<String, Object>();
   		// 号牌种类
   		List<SysCode> lstLicencePlateKind = spiSysCodeService.getSysCodeListByTypeCode(SysCodeType.PLATE_KIND);
   		model.put("lstLicencePlateKind", lstLicencePlateKind);
   		// 匹配方式
   		List<SysCode> lstMatchWay = spiSysCodeService.getSysCodeListByTypeCode(SysCodeType.MATCH_WAY);
   		model.put("lstlstMatchWay",lstMatchWay);
   
   		if(!StringUtils.isEmpty(specialPlateId)){
   			SpecialPlate specialPlate= specialPlateService.findById(specialPlateId);
   			model.put("specialPlate", specialPlate);
   		}
   		return new ModelAndView(SPE_PLA_EDT, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param specialPlate 
    * @param response
    * @exception Exception
    * @pdOid f71b38d4-de32-4615-9c99-9a66f023d111 */
   @RequestMapping(value = "/ajaxSaveSpecialPlate.do", method = RequestMethod.POST)
   public void handleAjaxSaveSpecialPlate(HttpServletRequest request, SpecialPlate specialPlate, HttpServletResponse response) throws Exception {
   	try {
   		specialPlateService.save(specialPlate);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   }
   
   /** @param request 
    * @param specialPlateIds 
    * @param response
    * @exception Exception
    * @pdOid 1d002124-c96c-461e-a7a0-e388d5dfa052 */
   @RequestMapping(value = "/ajaxDeleteSpecialPlateByIds.do", method = RequestMethod.POST)
   public void handleAjaxDeleteSpecialPlateByIds(HttpServletRequest request, String specialPlateIds, HttpServletResponse response) throws Exception {
   	try {
   		specialPlateService.delete(specialPlateIds);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   }

}